package com.platformer.controller;

import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.platformer.model.Hero;
import com.platformer.model.HeroState;
import com.platformer.view.HeroRenderer;

public class HeroController implements InputProcessor {
	
	private Hero hero;
	private HeroRenderer heroRenderer;
	
	
	public HeroController(Hero hero, HeroRenderer heroRenderer) {
		this.hero = hero;
		this.heroRenderer = heroRenderer;
	}
	
	public void update(float delta) {
		checkInputs();
		
		Vector2 v = hero.getWorldVector();
		if(v.x == 0) {
			hero.setState(HeroState.STANDING_RIGHT);
		} else if(v.x == 1) {
			hero.setState(HeroState.MOVING_RIGHT);
		} else if(v.x == -1) {
			hero.setState(HeroState.MOVING_LEFT);
		}
	}
	
	private void checkInputs() {
		if(Gdx.input.isKeyPressed(Keys.LEFT)) {
			hero.moveLeft();
		}
		if(Gdx.input.isKeyPressed(Keys.RIGHT)) {
			hero.moveRight();
		}
		
	}
	

	@Override
	public boolean keyDown(int keycode) {
		if(keycode == Keys.LEFT) {
			hero.moveLeft();
		}
		if(keycode == Keys.RIGHT) {
			hero.moveRight();
		}
		return false;
	}

	@Override
	public boolean keyUp(int keycode) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyTyped(char character) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean mouseMoved(int screenX, int screenY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean scrolled(int amount) {
		// TODO Auto-generated method stub
		return false;
	}

}
